package com.vogue.supplymall.account.shiro.realm;

import java.util.Collection;  

import org.apache.shiro.authc.AuthenticationInfo;  
import org.apache.shiro.authc.AuthenticationToken;  
import org.apache.shiro.authc.pam.AuthenticationStrategy;  
import org.apache.shiro.realm.Realm;  

/**
 * 多Realm链式传递验证只有一个生效<br>
 * 
 * @author 崔岳
 *
 */
public class ModularRealmAuthenticator extends org.apache.shiro.authc.pam.ModularRealmAuthenticator{

	@Override  
    protected AuthenticationInfo doMultiRealmAuthentication(Collection<Realm> realms, AuthenticationToken token) {  
          
        AuthenticationStrategy strategy = getAuthenticationStrategy();  
        AuthenticationInfo aggregate = strategy.beforeAllAttempts(realms, token);  
          
        for (Realm realm : realms) {  
            aggregate = strategy.beforeAttempt(realm, token, aggregate);  
            if (realm.supports(token)) {  
            	//咱们的验证框架是只有一个验证Realm会生效，所以，只走单realm验证模式即可
            	return this.doSingleRealmAuthentication(realm, token);
            } 
        	
        }  
        aggregate = strategy.afterAllAttempts(token, aggregate);  
        return aggregate;  
    }  
}
